﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using br.com.SistemaChamados.Controller;
using br.com.SistemaChamados.Model;
using br.com.SistemaChamados.Enum;

public partial class Pages_CallCategoryInsert : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnInsert_Click(object sender, EventArgs e)
    {
        CallCategory callCategory = new CallCategory();
        CallCategoryController controller = new CallCategoryController();

        try
        {
            if (controller.InsertCallCategory(populateObject(callCategory)) == EnumGenericState.GENERIC_STATE_SUCCESS)
            {
                Response.Write(@"<script language='javascript'>alert('Estado Cadastrado com Sucesso!');</script>");
                ClearFields();
            }
            else
            {
                Response.Write(@"<script language='javascript'>alert('Ocorreu um erro durante o cadastro, por favor tente novamente!');</script>");
            }
        }
        catch (Exception ex)
        {
            Response.Write(@"<script language='javascript'>alert('Ocorreu um erro no cadastro: <br>" + ex.Message +
                               ".');</script>");
            callCategory = null;
        }
    }

    public void ClearFields()
    {
        txbDescription.Text = "";
        txbMaximumTimeAnalize.Text = "";
        txbMaximumTimeTreatment.Text = "";
        txbMinimumTimeAnalize.Text = "";
        txbMinimumTimeTreatment.Text = "";
        txbDescription.Focus();
    }

    public CallCategory populateObject(CallCategory callCategory)
    {
        callCategory.Description = txbDescription.Text;
        callCategory.MaximumTimeAnalize = Convert.ToDouble(txbMaximumTimeAnalize.Text);
        callCategory.MaximumTimeTreatment = Convert.ToDouble(txbMaximumTimeTreatment.Text);
        callCategory.MinimumTimeAnalize = Convert.ToDouble(txbMinimumTimeAnalize.Text);
        callCategory.MinimumTimeTreatment = Convert.ToDouble(txbMinimumTimeTreatment.Text);

        return callCategory;
    }

}